home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / fips11.zip / TECHINFO.TXT < prev   
Text File  |  1993-11-07  |  9KB  |  228 lines

  1. Technical Info on FIPS
  2. ----------------------
  3.  
  4. FIPS was written in C++ V2.0 with the Turbo C++ 1.0 compiler.
  5. It should compile with any newer C++ compiler (perhaps after minor changes
  6. to the BIOS calls).
  7.  
  8. If you're a C++ wizard, don't look too closely at the code, this is my first
  9. C++ program, so it is far from acceptable (too much public data, some ini-
  10. tializers and assignment operators are missing etc.). Constructive Critizism
  11. is always welcome however.
  12.  
  13. How FIPS works:
  14.  
  15. FIPS uses the BIOS interrupts 13h 00h (reset disks), 13h 02h (read sector),
  16. 13h 08h (get drive parameters), 13h 03h (write sector) and 13h 04h (verify
  17. sector).
  18.  
  19. Here is the sequence of function calls in main:
  20.  
  21. evaluate_argument_vector
  22.   read the commandline arguments and set the global variables accordingly
  23. notice
  24.   display copyright notice and version number
  25. ask_for_drive_number
  26.   let the user choose the drive (if more than 1)
  27. harddrive.reset
  28.   reset harddrive
  29. harddrive.rootsector->read
  30.   read the sector 0,0,1 of the chosen drive into an array of unsigned char
  31. hd.partition_table().get
  32.   extract the necessary information from the rootsector (see below - The
  33.   Rootsector)
  34. hd.print_partition_table
  35.   print the information
  36. hd.check
  37.   check if everything is ok (see below - The Rootsector)
  38. ask_for_partition_number
  39.   let the user choose the partition
  40. partition->bootsector->read
  41.   read the first sector of the chosen partition to another array
  42. partition->bpb().get
  43.   extract info from the bootsector (see below - The Bootsector)
  44. partition->print_bpb
  45.   print the info
  46. partition->info().get
  47.   calculate no. of clusters, starting sector of FATs etc.
  48. partition->check
  49.   check bootsector (see below - The Bootsector)
  50. fat1.check_against(fat2)
  51.   check if FAT 1 is identical to FAT 2 (see below - The FAT)
  52. save_root_and_boot
  53.   write root- and bootsector to floppy disk (optional)
  54. ask_for_new_start_cylinder
  55.   ask the user for the first cylinder of the new partition
  56. fat2.check_empty
  57.   check if chosen part of partition is empty (see below - The FAT)
  58. hd.calculate_new_root
  59.   from the chosen start cylinder calculate the new partition table
  60.   Note that the partition entries will be moved to the beginning of the par- 
  61.   tition table, so that the new partition will be the last one and the drive
  62.   names will not change.
  63. hd.partition_table.put
  64.   write the new partition table into the rootsector-buffer
  65. hd.partition_table.get,hd.print_partition_table,hd.check
  66.   check if new rootsector is ok
  67. partition->calculate_new_boot
  68.   put new number of sectors in bootsector info
  69. partition->bpb()->put
  70.   write new bootsector info into bootsector-buffer
  71. partition->bpb()->get,partition->print_bpb,partition->check
  72.   check if new bootsector is ok
  73. ask_for_write_permission
  74.   ask if user wants to proceed
  75. harddrive.rootsector->writE
  76.   write the changed root sector to the disk
  77. partition->bootsector->write
  78.   write the changed boot sector to the disk
  79.  
  80.  
  81. The Rootsector
  82. --------------
  83.  
  84. The rootsector is the first sector on every hard disk. It contains the
  85. program that loads the bootsector of the bootable partition and the
  86. partition table. The last two bytes of the Rootsector must be 55 aa (hex).
  87. The partition table begins at 1be. It contains 4 * 16 Bytes for the four
  88. possible partitions.
  89. All numbers are zero based except the start/end-sector number (may be 1-63).
  90. One partition entry contains the following:
  91.  
  92. 1 Byte - Bootable Flag. Must be 0 (not bootable) or 80h (bootable).
  93.      At most one Partition may be bootable at a time.
  94.      (somewhere I read the bootable flag may also be 81h for the
  95.      second drive - does anybody know anything about that?)
  96.  
  97. 1 Byte - Start Head. The number of the head of the first sector of the
  98.      partition.
  99.  
  100. 2 Bytes - Start Sector + Cylinder. The Bits are as follows:
  101.  
  102.             CCSSSSSS CCCCCCCC
  103.  
  104.       where the first byte contains the sector number (1 - 63), and
  105.       the high two bits of the cylinder number. The second byte con-
  106.       tains the low eight bits of the cylinder number.
  107.  
  108. 1 Byte - System Indicator. For DOS this may be:
  109.  
  110.     1 - 12-bit FAT, 16-bit sector number
  111.     4 - 16-bit FAT, 16-bit sector number
  112.     5 - Extended Partition
  113.     6 - 16-bit FAT, 32-bit sector number
  114.  
  115. 1 Byte - End Head. Head Number of the last sector of the partition
  116.  
  117. 2 Bytes - End Sector + Cylinder. Same format as Start Sector + Cylinder
  118.  
  119. 4 Bytes - First Sector. Number of the first sector of the partition. This
  120.       corresponds to the Start Head, Sector + Cylinder. High Byte
  121.       comes first.
  122.  
  123. 4 Bytes - Total number of Sectors.
  124.  
  125. The function check_rootsector_validity checks the following:
  126.  
  127. - Signature Bytes (55 aa) in the last two bytes of the sector
  128. - not more than one bootable partition
  129. - Bootable flag is 0 or 80h
  130. - Start/End sector of a partition is not 0
  131. - Start/End sector & head are not greater than drive geometry allows
  132. - Start cylinder * sectors * heads + start head * sectors + start sector - 1
  133.   = first sector (where sectors is no. of sectors per track, heads is
  134.   no. of heads of the drive)
  135. - End cylinder * sectors * heads + end head * sector + end sector = first
  136.   sector + number of sectors
  137. - if System Indicator is 0, all other bytes of partition entry are 0
  138. - all partitions except the first begin on cylinder boundaries (head = 0,
  139.   sectors = 1)
  140. - all partition end on cylinder boundaries
  141. - partitions don't overlap
  142. - no free space between partitions
  143.  
  144.  
  145. The Bootsector
  146. --------------
  147.  
  148. The bootsector is the first sector of every partition. It contains the
  149. program that boots the operating system and the bios parameter block.
  150. The last two bytes must again contain 55 aa. The information in the
  151. bootsector is the following:
  152.  
  153. 00  3 bytes  jump instruction ('eb xx 90' or 'e9 xx xx')
  154. 03  8 bytes  OEM name and version - f.ex. MSDOS5.0
  155. 0b  2 bytes  bytes per sector - should be 512
  156. 0d  1 byte   sectors per cluster - power of two
  157. 0e  2 bytes  reserved sectors - typically 1 (bootsector)
  158. 10  1 byte   number of FATs - must be 2
  159. 11  2 bytes  number of rootdirectory entries - typically 512
  160. 13  2 bytes  number of sectors (short) - 0, if BIGDOS partition
  161. 15  1 byte   media descriptor - typically f8h
  162. 16  2 bytes  sectors per FAT - varies
  163. 18  2 bytes  sectors per track
  164. 1a  2 bytes  number of heads
  165. 1c  2 bytes  number of hidden sectors (low)
  166.  
  167. - extended BPB since DOS 4.0 -
  168.  
  169. 1e  2 bytes  number of hidden sectors (high)
  170. 20  4 bytes  number of sectors (long)
  171. 24  1 byte   physical drive number - 80h or 81h
  172. 25  1 byte   reserved
  173. 26  1 byte   signature - 29h
  174.  
  175. The function check_bootsector_validity checks the following:
  176.  
  177. - correct jump instruction
  178. - signature bytes 55 aa in the last two bytes of the sector
  179. - bytes per sector = 512
  180. - sectors per cluster is power of two
  181. - reserved sectors = 1
  182. - number of FATs = 2
  183. - number of rootdirectory entries is multiple of 16
  184. - media descriptor = f8h
  185. - sectors per fat <= 256
  186. - sectors per fat big enough to hold complete FAT
  187. - sectors per track matches BIOS info
  188. - number of heads matches BIOS info
  189. - hidden sectors = start sector
  190. - signature = 29h, if BIGDOS
  191. - physical drive number = actual drive number
  192. - number of sectors matches partition info
  193. - system indicator byte in rootsector matches partition type
  194.  
  195.  
  196. The FAT
  197. -------
  198.  
  199. The File Allocation Table contains the information how the clusters of the
  200. disk are linked to files. Every directory entry contains a pointer to the
  201. first cluster of the file. The corresponding cluster entry in the FAT contains
  202. a pointer to the next cluster, or an EOF marker (FFFF for 16-bit FATs, FFF for
  203. 12-bit FATs) if the cluster is the last one of the file.
  204. Bad clusters are marked with FFF7 or FF7. Empty clusters are marked with 0.
  205. The first cluster on the disk is cluster number 2, it begins at the first
  206. sector after the root directory. The FAT entries for the clusters 0 and 1
  207. contain the media descriptor byte (usually F8h for harddisk) and two or three
  208. FFh bytes.
  209. There exist two copies of the FAT on a normal DOS partition, these two copies
  210. must be identical. FAT 2 is the primary FAT.
  211.  
  212. The function check_fat_validity checks if